package com.thinkgem.jeesite.cn.yy.action;

import com.thinkgem.jeesite.cn.yy.service.ActLogService;
import com.thinkgem.jeesite.cn.yy.utils.Paging;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by jws24 on 2017/11/20.
 */
@Controller
@RequestMapping("ActLog")
public class ActLogAction {

    @Autowired
    private  ActLogService actLogService;



    private final Logger logger = LoggerFactory.getLogger(ActLogAction.class);

    /**
     * 查看日志的页
     * @param
     * @return
     */
    //
    @RequestMapping("getActLog")
    @ResponseBody

    public Map<String,Object> actLog (HttpServletRequest request) {
        int count = actLogService.getActLogPage();
        List<Map<String,String>> list=new ArrayList<Map<String, String>>();
        Map<String, Object> map = new HashMap();

        if (count == 0) {
            map.put("message", "ERROR");
            return map;
        } else {
            int first = Integer.parseInt(request.getSession().getServletContext().getAttribute("pageSize").toString());
            Paging paging = new Paging(0, first, count);
            List<Map<String, String>> actLogList = actLogService.getActLog(paging);
            System.out.println("______________________________________________________________");
            logger.info("{}", actLogList);
            if (actLogList != null) {

                map.put("message","OK");
                map.put("data",actLogList);

                return map;
            } else {
                map.put("message", "ERROR");
                return map;
            }
        }

    }
} 